package cn.db.service;

import cn.db.dao.StockDao;
import cn.db.entity.Stock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service
public class StockService {


    @Autowired
    private StockDao stockDao;

    public int insert(Stock info){
        stockDao.save(info);
        return 1;
    }

    public void preDecreaseStock(String orderNo,Integer skuId){
       Stock query = stockDao.queryBySkuId(skuId);
       if (Objects.isNull(query)){
           return;
       }
       int currentLockStock = query.getLockStock()+1;
       query.setLockStock(currentLockStock);
        stockDao.save(query);
    }
}
